using System;

//CID 0140 //2008.12.08 //Begin
namespace InfoJetSoft.Service.XPath.Tokens
{
	/// <summary>
	/// Summary description for CharUtil.
	/// </summary>
	class CharUtil
	{
		public static bool IsWhiteSpace( int code )
		{
			//[3]    S    ::=    (#x20 | #x9 | #xD | #xA)+ 
			if( code == 0x20 || code == 0x9 || code == 0xD || code == 0xA )
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
		public static bool IsDigit( int code )
		{
			// 0 - 9
			if( 48 <= code && code <= 57 )
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/*
		http://www.w3.org/TR/2006/REC-xml-20060816/
		*/
		//[5]    Name    ::=    (Letter | '_' | ':') (NameChar)* 
		public static bool IsNameStartChar10( int code )
		{
			//'_'
			if( code == 0x005F )
			{
				return true;
			}
			//[84]    Letter    ::=    BaseChar | Ideographic  
			//[85]    BaseChar 
			if( code >= 0x0041 && code <= 0x005A ||
				code >= 0x0061 && code <= 0x007A ||
				code >= 0x00C0 && code <= 0x00D6 ||
				code >= 0x00D8 && code <= 0x00F6 ||
				code >= 0x00F8 && code <= 0x00FF ||
				code >= 0x0100 && code <= 0x0131 ||
				code >= 0x0134 && code <= 0x013E ||
				code >= 0x0141 && code <= 0x0148 ||
				code >= 0x014A && code <= 0x017E ||
				code >= 0x0180 && code <= 0x01C3 ||
				code >= 0x01CD && code <= 0x01F0 ||
				code >= 0x01F4 && code <= 0x01F5 ||
				code >= 0x01FA && code <= 0x0217 ||
				code >= 0x0250 && code <= 0x02A8 ||
				code >= 0x02BB && code <= 0x02C1 ||
				code == 0x0386 ||
				code >= 0x0388 && code <= 0x038A ||
				code == 0x038C ||
				code >= 0x038E && code <= 0x03A1 ||
				code >= 0x03A3 && code <= 0x03CE ||
				code >= 0x03D0 && code <= 0x03D6 ||
				code == 0x03DA ||
				code == 0x03DC ||
				code == 0x03DE ||
				code == 0x03E0 ||
				code >= 0x03E2 && code <= 0x03F3 ||
				code >= 0x0401 && code <= 0x040C ||
				code >= 0x040E && code <= 0x044F ||
				code >= 0x0451 && code <= 0x045C ||
				code >= 0x045E && code <= 0x0481 ||
				code >= 0x0490 && code <= 0x04C4 ||
				code >= 0x04C7 && code <= 0x04C8 ||
				code >= 0x04CB && code <= 0x04CC ||
				code >= 0x04D0 && code <= 0x04EB ||
				code >= 0x04EE && code <= 0x04F5 ||
				code >= 0x04F8 && code <= 0x04F9 ||
				code >= 0x0531 && code <= 0x0556 ||
				code == 0x0559 ||
				code >= 0x0561 && code <= 0x0586 ||
				code >= 0x05D0 && code <= 0x05EA ||
				code >= 0x05F0 && code <= 0x05F2 ||
				code >= 0x0621 && code <= 0x063A ||
				code >= 0x0641 && code <= 0x064A ||
				code >= 0x0671 && code <= 0x06B7 ||
				code >= 0x06BA && code <= 0x06BE ||
				code >= 0x06C0 && code <= 0x06CE ||
				code >= 0x06D0 && code <= 0x06D3 ||
				code == 0x06D5 ||
				code >= 0x06E5 && code <= 0x06E6 ||
				code >= 0x0905 && code <= 0x0939 ||
				code == 0x093D ||
				code >= 0x0958 && code <= 0x0961 ||
				code >= 0x0985 && code <= 0x098C ||
				code >= 0x098F && code <= 0x0990 ||
				code >= 0x0993 && code <= 0x09A8 ||
				code >= 0x09AA && code <= 0x09B0 ||
				code == 0x09B2 ||
				code >= 0x09B6 && code <= 0x09B9 ||
				code >= 0x09DC && code <= 0x09DD ||
				code >= 0x09DF && code <= 0x09E1 ||
				code >= 0x09F0 && code <= 0x09F1 ||
				code >= 0x0A05 && code <= 0x0A0A ||
				code >= 0x0A0F && code <= 0x0A10 ||
				code >= 0x0A13 && code <= 0x0A28 ||
				code >= 0x0A2A && code <= 0x0A30 ||
				code >= 0x0A32 && code <= 0x0A33 ||
				code >= 0x0A35 && code <= 0x0A36 ||
				code >= 0x0A38 && code <= 0x0A39 ||
				code >= 0x0A59 && code <= 0x0A5C ||
				code == 0x0A5E ||
				code >= 0x0A72 && code <= 0x0A74 ||
				code >= 0x0A85 && code <= 0x0A8B ||
				code == 0x0A8D ||
				code >= 0x0A8F && code <= 0x0A91 ||
				code >= 0x0A93 && code <= 0x0AA8 ||
				code >= 0x0AAA && code <= 0x0AB0 ||
				code >= 0x0AB2 && code <= 0x0AB3 ||
				code >= 0x0AB5 && code <= 0x0AB9 ||
				code == 0x0ABD ||
				code == 0x0AE0 ||
				code >= 0x0B05 && code <= 0x0B0C ||
				code >= 0x0B0F && code <= 0x0B10 ||
				code >= 0x0B13 && code <= 0x0B28 ||
				code >= 0x0B2A && code <= 0x0B30 ||
				code >= 0x0B32 && code <= 0x0B33 ||
				code >= 0x0B36 && code <= 0x0B39 ||
				code == 0x0B3D ||
				code >= 0x0B5C && code <= 0x0B5D ||
				code >= 0x0B5F && code <= 0x0B61 ||
				code >= 0x0B85 && code <= 0x0B8A ||
				code >= 0x0B8E && code <= 0x0B90 ||
				code >= 0x0B92 && code <= 0x0B95 ||
				code >= 0x0B99 && code <= 0x0B9A ||
				code == 0x0B9C ||
				code >= 0x0B9E && code <= 0x0B9F ||
				code >= 0x0BA3 && code <= 0x0BA4 ||
				code >= 0x0BA8 && code <= 0x0BAA ||
				code >= 0x0BAE && code <= 0x0BB5 ||
				code >= 0x0BB7 && code <= 0x0BB9 ||
				code >= 0x0C05 && code <= 0x0C0C ||
				code >= 0x0C0E && code <= 0x0C10 ||
				code >= 0x0C12 && code <= 0x0C28 ||
				code >= 0x0C2A && code <= 0x0C33 ||
				code >= 0x0C35 && code <= 0x0C39 ||
				code >= 0x0C60 && code <= 0x0C61 ||
				code >= 0x0C85 && code <= 0x0C8C ||
				code >= 0x0C8E && code <= 0x0C90 ||
				code >= 0x0C92 && code <= 0x0CA8 ||
				code >= 0x0CAA && code <= 0x0CB3 ||
				code >= 0x0CB5 && code <= 0x0CB9 ||
				code == 0x0CDE ||
				code >= 0x0CE0 && code <= 0x0CE1 ||
				code >= 0x0D05 && code <= 0x0D0C ||
				code >= 0x0D0E && code <= 0x0D10 ||
				code >= 0x0D12 && code <= 0x0D28 ||
				code >= 0x0D2A && code <= 0x0D39 ||
				code >= 0x0D60 && code <= 0x0D61 ||
				code >= 0x0E01 && code <= 0x0E2E ||
				code == 0x0E30 ||
				code >= 0x0E32 && code <= 0x0E33 ||
				code >= 0x0E40 && code <= 0x0E45 ||
				code >= 0x0E81 && code <= 0x0E82 ||
				code == 0x0E84 ||
				code >= 0x0E87 && code <= 0x0E88 ||
				code == 0x0E8A ||
				code == 0x0E8D ||
				code >= 0x0E94 && code <= 0x0E97 ||
				code >= 0x0E99 && code <= 0x0E9F ||
				code >= 0x0EA1 && code <= 0x0EA3 ||
				code == 0x0EA5 ||
				code == 0x0EA7 ||
				code >= 0x0EAA && code <= 0x0EAB ||
				code >= 0x0EAD && code <= 0x0EAE ||
				code == 0x0EB0 ||
				code >= 0x0EB2 && code <= 0x0EB3 ||
				code == 0x0EBD ||
				code >= 0x0EC0 && code <= 0x0EC4 ||
				code >= 0x0F40 && code <= 0x0F47 ||
				code >= 0x0F49 && code <= 0x0F69 ||
				code >= 0x10A0 && code <= 0x10C5 ||
				code >= 0x10D0 && code <= 0x10F6 ||
				code == 0x1100 ||
				code >= 0x1102 && code <= 0x1103 ||
				code >= 0x1105 && code <= 0x1107 ||
				code == 0x1109 ||
				code >= 0x110B && code <= 0x110C ||
				code >= 0x110E && code <= 0x1112 ||
				code == 0x113C ||
				code == 0x113E ||
				code == 0x1140 ||
				code == 0x114C ||
				code == 0x114E ||
				code == 0x1150 ||
				code >= 0x1154 && code <= 0x1155 ||
				code == 0x1159 ||
				code >= 0x115F && code <= 0x1161 ||
				code == 0x1163 ||
				code == 0x1165 ||
				code == 0x1167 ||
				code == 0x1169 ||
				code >= 0x116D && code <= 0x116E ||
				code >= 0x1172 && code <= 0x1173 ||
				code == 0x1175 ||
				code == 0x119E ||
				code == 0x11A8 ||
				code == 0x11AB ||
				code >= 0x11AE && code <= 0x11AF ||
				code >= 0x11B7 && code <= 0x11B8 ||
				code == 0x11BA ||
				code >= 0x11BC && code <= 0x11C2 ||
				code == 0x11EB ||
				code == 0x11F0 ||
				code == 0x11F9 ||
				code >= 0x1E00 && code <= 0x1E9B ||
				code >= 0x1EA0 && code <= 0x1EF9 ||
				code >= 0x1F00 && code <= 0x1F15 ||
				code >= 0x1F18 && code <= 0x1F1D ||
				code >= 0x1F20 && code <= 0x1F45 ||
				code >= 0x1F48 && code <= 0x1F4D ||
				code >= 0x1F50 && code <= 0x1F57 ||
				code == 0x1F59 ||
				code == 0x1F5B ||
				code == 0x1F5D ||
				code >= 0x1F5F && code <= 0x1F7D ||
				code >= 0x1F80 && code <= 0x1FB4 ||
				code >= 0x1FB6 && code <= 0x1FBC ||
				code == 0x1FBE ||
				code >= 0x1FC2 && code <= 0x1FC4 ||
				code >= 0x1FC6 && code <= 0x1FCC ||
				code >= 0x1FD0 && code <= 0x1FD3 ||
				code >= 0x1FD6 && code <= 0x1FDB ||
				code >= 0x1FE0 && code <= 0x1FEC ||
				code >= 0x1FF2 && code <= 0x1FF4 ||
				code >= 0x1FF6 && code <= 0x1FFC ||
				code == 0x2126 ||
				code >= 0x212A && code <= 0x212B ||
				code == 0x212E ||
				code >= 0x2180 && code <= 0x2182 ||
				code >= 0x3041 && code <= 0x3094 ||
				code >= 0x30A1 && code <= 0x30FA ||
				code >= 0x3105 && code <= 0x312C ||
				code >= 0xAC00 && code <= 0xD7A3 )
			{
				return true;
			}
			//[86]    Ideographic 
			if( code >= 0x4E00 && code <= 0x9FA5 ||
				code == 0x3007 ||
				code >= 0x3021 && code <= 0x3029 )
			{
				return true;
			}
			return false;
		}

		//[4]    NameChar    ::=    Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender 
		public static bool IsNameChar10( int code )
		{
			//Letter
			if( IsNameStartChar10( code ) )
			{
				return true;
			}
			//Digit
			if( code >= 0x0030 && code <= 0x0039 ||
				code >= 0x0660 && code <= 0x0669 ||
				code >= 0x06F0 && code <= 0x06F9 ||
				code >= 0x0966 && code <= 0x096F ||
				code >= 0x09E6 && code <= 0x09EF ||
				code >= 0x0A66 && code <= 0x0A6F ||
				code >= 0x0AE6 && code <= 0x0AEF ||
				code >= 0x0B66 && code <= 0x0B6F ||
				code >= 0x0BE7 && code <= 0x0BEF ||
				code >= 0x0C66 && code <= 0x0C6F ||
				code >= 0x0CE6 && code <= 0x0CEF ||
				code >= 0x0D66 && code <= 0x0D6F ||
				code >= 0x0E50 && code <= 0x0E59 ||
				code >= 0x0ED0 && code <= 0x0ED9 ||
				code >= 0x0F20 && code <= 0x0F29 )
			{
				return true;
			}
			//'.' | '-' | '_' 
			if( code == 0x002E || code == 0x002D || code == 0x005F )
			{
				return true;
			}
			//CombiningChar
			if( code >= 0x0300 && code <= 0x0345 ||
				code >= 0x0360 && code <= 0x0361 ||
				code >= 0x0483 && code <= 0x0486 ||
				code >= 0x0591 && code <= 0x05A1 ||
				code >= 0x05A3 && code <= 0x05B9 ||
				code >= 0x05BB && code <= 0x05BD ||
				code == 0x05BF ||
				code >= 0x05C1 && code <= 0x05C2 ||
				code == 0x05C4 ||
				code >= 0x064B && code <= 0x0652 ||
				code == 0x0670 ||
				code >= 0x06D6 && code <= 0x06DC ||
				code >= 0x06DD && code <= 0x06DF ||
				code >= 0x06E0 && code <= 0x06E4 ||
				code >= 0x06E7 && code <= 0x06E8 ||
				code >= 0x06EA && code <= 0x06ED ||
				code >= 0x0901 && code <= 0x0903 ||
				code == 0x093C ||
				code >= 0x093E && code <= 0x094C ||
				code == 0x094D ||
				code >= 0x0951 && code <= 0x0954 ||
				code >= 0x0962 && code <= 0x0963 ||
				code >= 0x0981 && code <= 0x0983 ||
				code == 0x09BC ||
				code == 0x09BE ||
				code == 0x09BF ||
				code >= 0x09C0 && code <= 0x09C4 ||
				code >= 0x09C7 && code <= 0x09C8 ||
				code >= 0x09CB && code <= 0x09CD ||
				code == 0x09D7 ||
				code >= 0x09E2 && code <= 0x09E3 ||
				code == 0x0A02 ||
				code == 0x0A3C ||
				code == 0x0A3E ||
				code == 0x0A3F ||
				code >= 0x0A40 && code <= 0x0A42 ||
				code >= 0x0A47 && code <= 0x0A48 ||
				code >= 0x0A4B && code <= 0x0A4D ||
				code >= 0x0A70 && code <= 0x0A71 ||
				code >= 0x0A81 && code <= 0x0A83 ||
				code == 0x0ABC ||
				code >= 0x0ABE && code <= 0x0AC5 ||
				code >= 0x0AC7 && code <= 0x0AC9 ||
				code >= 0x0ACB && code <= 0x0ACD ||
				code >= 0x0B01 && code <= 0x0B03 ||
				code == 0x0B3C ||
				code >= 0x0B3E && code <= 0x0B43 ||
				code >= 0x0B47 && code <= 0x0B48 ||
				code >= 0x0B4B && code <= 0x0B4D ||
				code >= 0x0B56 && code <= 0x0B57 ||
				code >= 0x0B82 && code <= 0x0B83 ||
				code >= 0x0BBE && code <= 0x0BC2 ||
				code >= 0x0BC6 && code <= 0x0BC8 ||
				code >= 0x0BCA && code <= 0x0BCD ||
				code == 0x0BD7 ||
				code >= 0x0C01 && code <= 0x0C03 ||
				code >= 0x0C3E && code <= 0x0C44 ||
				code >= 0x0C46 && code <= 0x0C48 ||
				code >= 0x0C4A && code <= 0x0C4D ||
				code >= 0x0C55 && code <= 0x0C56 ||
				code >= 0x0C82 && code <= 0x0C83 ||
				code >= 0x0CBE && code <= 0x0CC4 ||
				code >= 0x0CC6 && code <= 0x0CC8 ||
				code >= 0x0CCA && code <= 0x0CCD ||
				code >= 0x0CD5 && code <= 0x0CD6 ||
				code >= 0x0D02 && code <= 0x0D03 ||
				code >= 0x0D3E && code <= 0x0D43 ||
				code >= 0x0D46 && code <= 0x0D48 ||
				code >= 0x0D4A && code <= 0x0D4D ||
				code == 0x0D57 ||
				code == 0x0E31 ||
				code >= 0x0E34 && code <= 0x0E3A ||
				code >= 0x0E47 && code <= 0x0E4E ||
				code == 0x0EB1 ||
				code >= 0x0EB4 && code <= 0x0EB9 ||
				code >= 0x0EBB && code <= 0x0EBC ||
				code >= 0x0EC8 && code <= 0x0ECD ||
				code >= 0x0F18 && code <= 0x0F19 ||
				code == 0x0F35 ||
				code == 0x0F37 ||
				code == 0x0F39 ||
				code == 0x0F3E ||
				code == 0x0F3F ||
				code >= 0x0F71 && code <= 0x0F84 ||
				code >= 0x0F86 && code <= 0x0F8B ||
				code >= 0x0F90 && code <= 0x0F95 ||
				code == 0x0F97 ||
				code >= 0x0F99 && code <= 0x0FAD ||
				code >= 0x0FB1 && code <= 0x0FB7 ||
				code == 0x0FB9 ||
				code >= 0x20D0 && code <= 0x20DC ||
				code == 0x20E1 ||
				code >= 0x302A && code <= 0x302F ||
				code == 0x3099 ||
				code == 0x309A )
			{
				return true;
			}
			//Extender
			if(	code == 0x00B7 ||
				code == 0x02D0 ||
				code == 0x02D1 ||
				code == 0x0387 ||
				code == 0x0640 ||
				code == 0x0E46 ||
				code == 0x0EC6 ||
				code == 0x3005 ||
				code >= 0x3031 && code <= 0x3035 ||
				code >= 0x309D && code <= 0x309E ||
				code >= 0x30FC && code <= 0x30FE )
			{
				return true;
			}
			return false;
		}
	}
}
//CID 0140 //2008.12.08 //End
